import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


public class P23 {
	public static boolean isAbundant(int n) {
		int sum = 0;
		for (int i = 1; i <= n/2; i++) {
			if (n % i == 0) {
				sum += i;
			}
		}
		
		return sum > n; 
	}
	
	public static boolean isSumable(int n, Map<Integer, Integer> abundantList) {
		for (Iterator iterator = abundantList.keySet().iterator(); iterator.hasNext();) {
			if (abundantList.containsKey(n - abundantList.get(iterator.next()))) {
				return true;
			}
		}		
		return false;
	}
	
	public static void main(String[] args) {
		long sum = 0;
		Map<Integer, Integer> abundantList = new HashMap<Integer, Integer>();
		
		for (int i = 1; i <= 28123; i++) {
			if (isAbundant(i)) {
				abundantList.put(i, i);
			}
			
			if (!isSumable(i, abundantList)) {
				System.out.println(i);
				sum += i;
			}
		}
		System.out.println(sum);
	}
}
